/**
 * 插入排序（从排好序的队伍一端，插入）
 */
public class InsertionSort {
    //程序1
    private static void insertionSort1(int[] arr) {
        //边界判断
        if (arr == null || arr.length < 2) {
            return;
        }
        //0~1,0~2,0~3...0~N
        int N = arr.length;
        for (int end = 1; end < N; end++) {
            //
            for (int i = end; i > 0; i--) {
                if (arr[i] > arr[i - 1]) {
                    break;
                }
                int midValue = arr[i];
                arr[i] = arr[i - 1];
                arr[i - 1] = midValue;
            }
            print(arr);
        }
    }

    //程序2
    public static void insertionSort2(int[] arr) {
        //边界判断
        if (arr == null || arr.length < 2) {
            return;
        }
        int N = arr.length;
        for (int end = 0; end < N; end++) {
            int newNumIndex = end;
            while (newNumIndex - 1 >= 0 && arr[newNumIndex - 1] > arr[newNumIndex]) {
                int midValue = arr[newNumIndex - 1];
                arr[newNumIndex - 1] = arr[newNumIndex];
                arr[newNumIndex] = midValue;
                newNumIndex--;
            }
            print(arr);
        }
    }

    public static void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        int[] arr = {3, 5, 3, 4, 5, 5, 5, 4, 7, 2, 6, 2, 4, 3, 8, 4, 9, 5, 1};
        print(arr);
        System.out.println("插入排序算法过程：");
        //insertionSort1(arr);
        //insertionSort2(arr);
        dome(arr);
        System.out.println();
        print(arr);
    }
    //练习
    public static void dome(int[] arr) {
        //边界
        if (arr == null || arr.length < 2) {
            return;
        }

    }














}
